<?php
/*
PLUGIN NAME: About Widget
PLUGIN URI: http://wp-plugin-dev.googlecode.com/
DESCRIPTION: Displays filtered HTML text on page views outside of the front page and the blog page. Great for 'about' text. For WordPress 2.6.x.
AUTHOR: Scott Allan Wallick
AUTHOR URI: http://scottwallick.com/
VERSION: 0.1.0 &beta;
*/

/*
ABOUT WIDGET
by SCOTT ALLAN WALLICK, http://scottwallick.com/
from PLAINTXT.ORG, http://www.plaintxt.org/

ABOUT WIDGET is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.

ABOUT WIDGET is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for details.

You should have received a copy of the GNU General Public License
along with ABOUT WIDGET. If not, see www.gnu.org/licenses/.
*/

function widget_about_text($args) {
	extract($args);
	$options = get_option('widget_about_text');
	$title   = apply_filters( 'widget_title', $options['title'] );
	$text    = apply_filters( 'widget_text', $options['text'] );
	if ( !( is_front_page() || is_home() ) ) {
		echo $before_widget;
		echo $before_title . $title . $after_title;
		echo '<div class="textwidget abouttext">' . $text . '</div>';
		echo $after_widget;
	}
}

function widget_about_text_control() {
	$options = $newoptions = get_option('widget_about_text');
	if ( $_POST['about-text-submit'] ) {
		$newoptions['title'] = strip_tags(stripslashes($_POST['about-text-title']));
		if ( current_user_can('unfiltered_html') ) {
			$newoptions['text'] = stripslashes($_POST['about-text-text']);
		} else {
			$newoptions['text'] = strip_tags(stripslashes($_POST['about-text-text']));
		}
	}
	if ( $options != $newoptions ) {
		$options = $newoptions;
		update_option( 'widget_about_text', $options );
	}
	$text = format_to_edit($options['text']);
	$title = attribute_escape($options['title']);
?>
	<p>
		<label for="about-text-title"><?php _e( 'Title:', 'aboutw' ) ?> <input class="widefat" id="about-text-title" name="about-text-title" type="text" value="<?php echo $title; ?>" /></label>
		<textarea class="widefat" rows="16" cols="20" id="about-text-text" name="about-text-text"><?php echo $text; ?></textarea>
		<input type="hidden" id="about-text-submit" name="about-text-submit" value="1" />
	</p>
<?php
}

function widget_about_text_register() {
	$widget_ops = array(
		'classname'    =>  'widget_about_text',
		'description'  =>  __( 'Displays about text outside the front/blog home pages', 'aboutw' )
	);

	$control_ops = array(
		'width'   => 400,
		'height'  => 350,
		'id_base' => 'about_text'
	);

	$name = __( 'About Text', 'aboutw' );

	wp_register_sidebar_widget( 'about_text', $name, 'widget_about_text', $widget_ops );
	wp_register_widget_control( 'about_text', $name, 'widget_about_text_control', $control_ops );
}

// If deactivating plugin, remove its table entry
function widget_about_text_deactivation() {
	delete_option('widget_about_text');
}

// Allow localization. Which I doubt will be used. (Sorry.)
load_theme_textdomain('aboutw');

// Initializes the function to add widgets to WordPress
add_action( 'init', 'widget_about_text_register' );

// If deactivating, run the wp_aboutw_deactivation() function
register_deactivation_hook( __FILE__, 'widget_about_text_deactivation' );
?>